
#include "AlgebraFactory.h"
#include "TableAlgebra.h"

IAlgebra* AlgebraFactory::CreateAlgebra(WORD n, BYTE** addition_table, BYTE** multiplication_table)
{
	return new TableAlgebra(n, addition_table, multiplication_table);
}

IAlgebra* AlgebraFactory::CreateAlgebra(const std::string &path)
{
	FILE *file = fopen(path.c_str(), "rb");
	if (file==NULL)
	{
		return 0;
	}
	BYTE one;
	BYTE nil;
	fread(&nil, 1, 1, file);
	fread(&one, 1, 1, file);
	BYTE **addition_table = new BYTE*[256];
	BYTE **multiplication_table = new BYTE*[256];
	for(int i = 0; i < 256; i++)
	{
		addition_table[i] = new BYTE[256];
		fread(addition_table[i], 1, 256, file);
	}
	for(int i = 0; i < 256; i++)
	{
		multiplication_table[i] = new BYTE[256];
		fread(multiplication_table[i], 1, 256, file);
	}
	fclose(file);
	return new TableAlgebra(256, addition_table, multiplication_table);
}
